<template>
	<view class="container">
		<tui-loading v-show="!pageData.loading"></tui-loading>
		<view class="page" v-show="pageData.loading" :style="{ marginTop: header.init.height + 'px' }">
			<tui-navigation-bar @init="initNavigation" @change="changeNavigation" :title="header.title" :color="tui.getColorSite().title.color" :backgroundColor="tui.getColorSite().title.backgroundColor" :splitLine="header.splitLine" :isOpacity="header.isOpacity" :maxOpacity="header.maxOpacity" :transparent="header.transparent" :scrollTop="header.scrollTop" :scrollRatio="header.scrollRatio" :isCustom="header.isCustom" :isImmersive="header.isImmersive" :isFixed="header.isFixed" :backdropFilter="header.backdropFilter" :dropDownHide="header.dropDownHide" :zIndex="header.zIndex">
				<view class="tui-header-icon" :style="{ top: header.init.top + 'px' }">
					<tui-icon name="arrowleft" :color="tui.getColorSite().title.color" @click="back"></tui-icon>
				</view>
			</tui-navigation-bar>
			<view v-if="tui.inArray(get.tpl, ['address'])">
				<tui-input label="收货人" required :lineLeft="false" type="text" clearable placeholder="请输入收货人姓名" v-model="param[get.tpl].full_name" confirmType="done"></tui-input>
				<tui-input label="手机号" required :lineLeft="false" type="number" clearable placeholder="请输入收货人手机号" v-model="param[get.tpl].phone" maxlength="11" confirmType="done"></tui-input>
				<tui-form-item label="地区" :asterisk="true" left="0" right="0" borderColor="#F1F1F1" :arrow="true" :highlight="true">
					<template v-slot:default>
						<picker mode="multiSelector" :value="pageData.site.addressValue" @change="p2c2dInit" @columnchange="changePicker" :range="pageData.site.multiArray">
							<view>
								{{pageData.site.addressValueString}}
							</view>
						</picker>
					</template>
				</tui-form-item>
				<tui-textarea required label="详细地址" autoHeight placeholder="请输入详细的详细地址" v-model="param[get.tpl].info" flexStart isCounter confirmType="done"></tui-textarea>
				<tui-form-item label="设置默认">
					<template v-slot:right>
						<tui-switch :scaleRatio="0.8" @change="saveSwitch" :checked="(param[get.tpl].is_default == 1) ? true : false" color="#eb0910"></tui-switch>
					</template>
				</tui-form-item>
				<view class="tui-form-button">
					<tui-button shadow shape="circle" :type="tui.getColorSite().button.type" height="88rpx" @click="formSubmit()">保存</tui-button>
				</view>
			</view>
			<view v-else-if="tui.inArray(get.tpl, ['wallet'])">
				<tui-input label="当前拥有" labelColor="#eb0910" color="#eb0910" :lineLeft="false" type="text" :labelSize="28" :size="28" :value="pageData.wallet.now_have" disabled></tui-input>
				<tui-input :label="pageData.wallet.chequesName" labelColor="#eb0910" color="#eb0910" :lineLeft="false" type="text" :labelSize="28" :size="28" :value="pageData.wallet.cheques" disabled v-if="pageData.wallet.cheques!=='‘'"></tui-input>
				<tui-input label="开户姓名" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的开户姓名" v-model="param[get.tpl][get.key].account_name" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input label="实名手机" :lineLeft="false" type="number" :labelSize="28" :size="28" clearable placeholder="请输入您的实名手机" v-model="param[get.tpl][get.key].name_phone" maxlength="11" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input label="开户银行" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的开户银行" v-model="param[get.tpl][get.key].bank_of_deposit" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input label="开户支行" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的开户支行" v-model="param[get.tpl][get.key].bank_subbranch_of_deposit" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input label="银行卡号" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的银行卡号" v-model="param[get.tpl][get.key].bank_no" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input label="身份账号" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的身份账号" v-model="param[get.tpl][get.key].id_card" maxlength="18" confirmType="done" v-if="tui.inArray(get.key, ['commission'])"></tui-input>
				<tui-input :label="pageData.wallet.operate_name" :lineLeft="false" type="number" :labelSize="28" :size="28" clearable :placeholder="'请输入您的'+pageData.wallet.operate_name" v-model="param[get.tpl][get.key].price" confirmType="done"></tui-input>
				<tui-input label="接收人账号" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的接收人账号" v-model="param[get.tpl][get.key].to_member_username" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['u_species'])"></tui-input>
				<tui-input label="备注说明" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="选填: 请输入备注说明..." v-model="param[get.tpl][get.key].remarks" confirmType="done"></tui-input>
				<view class="tui-form-button">
					<tui-button shadow shape="circle" :type="tui.getColorSite().button.type" height="88rpx" @click="formSubmit()">提交</tui-button>
				</view>
			</view>
			<view v-else-if="tui.inArray(get.tpl, ['recharge'])">
				<tui-input :label="pageData.recharge.operate_name" :lineLeft="false" type="number" :labelSize="28" :size="28" clearable :placeholder="'请输入您的'+pageData.recharge.operate_name" v-model="param[get.tpl][get.key].price" confirmType="done"></tui-input>
				<tui-input label="接收人账号" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="请输入您的接收人账号" v-model="param[get.tpl][get.key].to_member_username" maxlength="30" confirmType="done" v-if="tui.inArray(get.key, ['u_species'])"></tui-input>
				<tui-input label="备注说明" :lineLeft="false" type="text" :labelSize="28" :size="28" clearable placeholder="选填: 请输入备注说明..." v-model="param[get.tpl][get.key].remarks" confirmType="done"></tui-input>
				<view class="tui-form-button">
					<tui-button shadow shape="circle" :type="tui.getColorSite().button.type" height="88rpx" @click="formSubmit()">提交</tui-button>
				</view>
			</view>
			<view v-else-if="tui.inArray(get.tpl, ['manage_password','password'])">
				<tui-input label="通知手机号" :lineLeft="false" type="text" :labelSize="28" :size="28" :value="pageData.btnSendCode.paramValue" disabled></tui-input>
				<tui-input label="操作密码" :lineLeft="false" type="paddword" :labelSize="28" :size="28" clearable placeholder="请输入操作密码" v-model="param[get.tpl].paddword"></tui-input>
				<tui-input label="验证码" :lineLeft="false" type="number" :labelSize="28" :size="28" placeholder="请输入验证码" v-model="param[get.tpl].code">
					<template v-slot:right>
						<view style="padding-left: 20rpx;">
							<tui-button width="182rpx" height="56rpx" :size="24" shape="circle" plain :type="tui.getColorSite().button.type" :disabled="pageData.btnSendCode.disabled" @click="btnSendCode">{{ pageData.btnSendCode.btnText }}</tui-button>
						</view>
					</template>
				</tui-input>
				<view class="tui-form-button">
					<tui-button shadow shape="circle" :type="tui.getColorSite().button.type" height="88rpx" @click="formSubmit()">提交</tui-button>
				</view>
			</view>
			<view v-else-if="tui.inArray(get.tpl, ['publicUserDetail'])">
				<tui-form-item :labelWidth="320" label="头像" @click="changeAvatar">
					<template v-slot:right>
						<view class="member_portrait">
							<image :src="param[get.tpl].portrait.url ? param[get.tpl].portrait.url : 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132'" class="img"></image>
						</view>
					</template>
				</tui-form-item>
				<tui-input label="会员昵称" textRight='true' :lineLeft="false" type="text" :labelSize="28" :size="28" placeholder="请输入您的会员昵称" v-model="param[get.tpl].nick_name" maxlength="11" confirmType="done"></tui-input>
				<tui-input label="真实姓名" textRight='true' :lineLeft="false" type="text" :labelSize="28" :size="28" placeholder="请输入您的真实姓名" v-model="param[get.tpl].real_name" maxlength="11" confirmType="done"></tui-input>
				<tui-input label="联系电话" textRight='true' :lineLeft="false" type="text" :labelSize="28" :size="28" placeholder="请输入您的联系电话" v-model="param[get.tpl].tel" maxlength="11" confirmType="done"></tui-input>

				<tui-form-item label="性别" left="0" right="0" borderColor="#F1F1F1">
					<template v-slot:right>
						<radio-group class="tui-radio-group" v-model="param[get.tpl].sex" @change="onChangeGender">
							<label class="tui-radio-item">
								<radio value="1" :color="tui.getColorSite().radio.color" :checked="(param[get.tpl].sex == 1 ? true : false)" />男
							</label>
							<label class="tui-radio-item">
								<radio value="2" :color="tui.getColorSite().radio.color" :checked="(param[get.tpl].sex == 2 ? true : false)" />女
							</label>
						</radio-group>
					</template>
				</tui-form-item>
				<view class="tui-form-button">
					<tui-button shadow shape="circle" :type="tui.getColorSite().button.type" height="88rpx" @click="formSubmit()">提交</tui-button>
				</view>
			</view>
			<view v-else>
				<tui-input label="文本" required :lineLeft="false" type="text" clearable placeholder="请输入XXXXXX" confirmType="done"></tui-input>
				<tui-input label="数字" required :lineLeft="false" type="number" clearable placeholder="请输入XXXXXX" confirmType="done"></tui-input>
				<tui-form-item label="文本域" :asterisk="true" left="0" right="0" borderColor="#F1F1F1">
				</tui-form-item>
				<tui-textarea height="40rpx" min-height="40rpx" label="简介" placeholder="请输入一句话简介"></tui-textarea>
			</view>


			<tui-keyboard :show="pageData.keyboard.status" @close="closeKeyboard" @click="keyboardClick">
				<view class="tui-digital-box">
					<view class="tui-keyboard-tips">请输入密码</view>
					<tui-keyboard-input :inputvalue="pageData.keyboard.inputArr"></tui-keyboard-input>
				</view>
			</tui-keyboard>
		</view>
	</view>
</template>

<script>
	import formCheck from '@/components/common/tui-validation/tui-validation.js'
	import pickerCity from '@/common/picker.city.js'
	export default {
		data() {
			return {
				get: {},
				header: {
					title: 'Form', //NavigationBar标题
					splitLine: false, //是否需要分割线
					isOpacity: false, //是否设置不透明度
					maxOpacity: 1, //不透明度最大值 0-1
					transparent: false, //背景透明 （设置该属性，则背景透明，只出现内容，isOpacity和maxOpacity失效）
					scrollTop: 0.5, //滚动条滚动距离
					scrollRatio: 0.3, //isOpacity 为true时生效（opacity=scrollTop /windowWidth * scrollRatio）
					isCustom: false, //是否自定义NavigationBar内容
					isImmersive: true, //是否沉浸式,
					isFixed: true, //是否固定
					backdropFilter: false, //是否开启高斯模糊效果[仅在支持的浏览器有效果]，为true时maxOpacity设置小于1的值
					dropDownHide: false, //下拉隐藏NavigationBar，主要针对有回弹效果ios端
					zIndex: 9998, //z-index值
					init: {
						width: 0,
						height: 0,
						left: 0,
						top: 0,
						top: 0,
						scrollH: 0,
					},
				},
				pageData: {
					loading: false,
					wallet: {
						now_have: '0.00',
						cheques: '',
						chequesName: '',
						operate_name: '操作数量',
					},
					recharge: {
						operate_name: '充值数量',
					},
					keyboard: {
						status: false,
						numberArr: [],
						//数组长度表示显示输入框的个数
						inputArr: ["", "", "", "", "", ""],
						tempArr: ["", "", "", "", "", ""],
						radius: false
					},
					btnSendCode: {
						disabled: false,
						timeSite: 60,
						btnText: '获取验证码',
						type: '',
						paramValue: '',
					},
					site: {
						selectList: pickerCity,
						multiArray: [], //picker数据
						addressValue: [0, 0, 0],
						addressValueString: '请选择省、市、区',
					},
				},
				param: {
					address: {
						full_name: '',
						phone: '',
						info: '',
						province: '',
						city: '',
						district: '',
						is_default: 0,
					},
					wallet: {
						commission: {
							account_name: '',
							name_phone: '',
							bank_of_deposit: '',
							bank_subbranch_of_deposit: '',
							bank_no: '',
							id_card: '',
							price: '',
							remarks: '',
						},
						u_species: {
							price: '',
							remarks: '',
							to_member_username: '',
						},
						integral: {
							price: '',
						},
					},
					recharge: {
						u_species: {
							price: '',
							remarks: '',
							to_member_username: '',
						},
					},
					publicUserDetail: {
						nick_name: '',
						real_name: '',
						tel: '',
						sex: 1,
						portrait: {},
					},
					manage_password: {
						paddword: '',
						code: '',
					},
					password: {
						paddword: '',
						code: '',
					},
				},
				xhrUrl: '',
				appInit: {},
				user: {},
			}
		},
		// 监听页面加载，其参数为上个页面传递的数据，参数类型为 Object（用于页面传参）
		onLoad(e) {
			let that = this;
			// uni.startPullDownRefresh();
			console.log("self:onLoad++++++++++++++++++++++++++++++++++++++++++++++++++");
			uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			if (typeof(e.scene) != 'undefined') {
				e = that.tui.getUrlkey(decodeURIComponent(e.scene));
			}
			that.get = e;
			if (typeof that.get.title !== 'undefined') {
				that.header.title = that.get.title;
				if (that.header.title.length > 13) {
					that.header.title = that.header.title.slice(0, 13) + '...';
				}
			}
			switch (that.get.tpl) {
				case 'address':
					if (typeof(that.get.address_id) == 'undefined') {
						that.get.address_id = 0;
					}
					break;
				default:
					break;
			}
			console.log("self:getData=>", that.get);
			let obj = {};
			uni.getSystemInfo({
				success: function(res) {
					that.header.init.width = obj.left || res.windowWidth;
					that.header.init.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight + 44;
					that.header.init.top = obj.top ? obj.top + (obj.height - 32) / 2 : res.statusBarHeight + 6;
					that.header.init.scrollH = res.windowWidth * 0.6;
				}
			});
			switch (that.get.tpl) {
				case 'address':
					that.xhrUrl = '/user/address';
					break;
				case 'wallet':
					that.xhrUrl = '/user/wallet';
					break;
				case 'recharge':
					that.xhrUrl = '/user/wallet';
					break;
				case 'publicUserDetail':
					that.xhrUrl = '/user/init';
					break;
				default:
					break;
			}
			that.$forceUpdate();
			that.initialize();
		},
		// 监听页面显示。页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面
		onShow() {
			let that = this;
		},
		// 监听页面滚动，参数为Object
		onPageScroll(e) {
			let that = this;
			that.header.scrollTop = e.scrollTop;
			that.$forceUpdate();
		},
		methods: {
			initialize() {
				let that = this;
				let Int = setInterval(function() {
					that.user = that.tui.getCache("user");
					console.log('self:user=>', that.user);
					if (typeof(that.user) == 'object') {
						clearInterval(Int);
						that.__init();
					}
				}, 800);
			},
			async __init() {
				let that = this;
				that.appInit = that.tui.getCache("appInit");
				console.log('self:appInit=>', that.appInit);
				switch (that.get.tpl) {
					case 'address':
						if (that.tui.isDebug()) {
							that.param[that.get.tpl].full_name = '测试' + that.tui.formatDate().timestamp;
							that.param[that.get.tpl].phone = '13110447185';
							that.param[that.get.tpl].info = '北院门街道西安钟楼';
							that.param[that.get.tpl].province = '陕西省';
							that.param[that.get.tpl].city = '西安市';
							that.param[that.get.tpl].district = '未央区';
							that.pageData.site.addressValueString = '陕西省 西安市 未央区';
						}
						that.param[that.get.tpl].id = parseInt(that.get.address_id);
						that.pageData.site.multiArray = [];
						that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList))
						that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[0].childlist))
						that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[0].childlist[0].childlist))
						if (that.param[that.get.tpl].id === 0) {
							that.pageData.site.selectList.forEach(function(v, k) {
								if (v.name === that.param[that.get.tpl].province) {
									that.pageData.site.multiArray = [];
									that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList));
									that.pageData.site.addressValue = [];
									that.pageData.site.addressValue.push(k);
									v.childlist.forEach(function(vv, vk) {
										if (vv.name === that.param[that.get.tpl].city) {
											that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[k].childlist));
											that.pageData.site.addressValue.push(vk);
											vv.childlist.forEach(function(vvv, vvk) {
												if (vvv.name === that.param[that.get.tpl].district) {
													that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[k].childlist[vk].childlist));
													that.pageData.site.addressValue.push(vvk);
												}
											});
										}
									});
								}
							});
						} else {
							let getAddressInfo = await that.tui.get(that.xhrUrl, {
								id: that.param[that.get.tpl].id
							})
							if (getAddressInfo.status === 0) {
								that.param[that.get.tpl].full_name = getAddressInfo.data.full_name;
								that.param[that.get.tpl].phone = getAddressInfo.data.phone;
								that.param[that.get.tpl].info = getAddressInfo.data.info;
								that.param[that.get.tpl].province = getAddressInfo.data.province;
								that.param[that.get.tpl].city = getAddressInfo.data.city;
								that.param[that.get.tpl].district = getAddressInfo.data.district;
								that.param[that.get.tpl].is_default = getAddressInfo.data.is_default;
								that.pageData.site.addressValueString = [];
								that.pageData.site.addressValueString.push(that.param[that.get.tpl].province);
								that.pageData.site.addressValueString.push(that.param[that.get.tpl].city);
								that.pageData.site.addressValueString.push(that.param[that.get.tpl].district);
								that.pageData.site.addressValueString = that.tui.arr2str(that.pageData.site.addressValueString, ' ');
								that.pageData.site.selectList.forEach(function(v, k) {
									if (v.name === that.param[that.get.tpl].province) {
										that.pageData.site.multiArray = [];
										that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList));
										that.pageData.site.addressValue = [];
										that.pageData.site.addressValue.push(k);
										v.childlist.forEach(function(vv, vk) {
											if (vv.name === that.param[that.get.tpl].city) {
												that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[k].childlist));
												that.pageData.site.addressValue.push(vk);
												vv.childlist.forEach(function(vvv, vvk) {
													if (vvv.name === that.param[that.get.tpl].district) {
														that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[k].childlist[vk].childlist));
														that.pageData.site.addressValue.push(vvk);
													}
												});
											}
										});
									}
								});
							}
						}
						break;
					case 'recharge':
						if (that.tui.isDebug()) {
							that.param[that.get.tpl][that.get.key].price = '1000';
							that.param[that.get.tpl][that.get.key].remarks = '备注' + that.tui.formatDate().format;
						}
						switch (that.get.key) {
							case 'u_species':
								if (that.tui.isDebug()) {
									that.param[that.get.tpl][that.get.key].to_member_username = '13100000154';
								}
								break;
						}
						break;
					case 'wallet':
						if (that.tui.isDebug()) {
							that.param[that.get.tpl][that.get.key].price = '1000';
							that.param[that.get.tpl][that.get.key].remarks = '备注' + that.tui.formatDate().format;
						}
						switch (that.get.key) {
							case 'u_species':
								that.pageData.wallet.now_have = parseInt(that.user.userInfo[that.get.key]) + '枚';
								that.pageData.wallet.operate_name = '转赠数量';
								if (that.tui.isDebug()) {
									that.param[that.get.tpl][that.get.key].to_member_username = '13100000153';
								}
								break;
							case 'commission':
								that.pageData.wallet.now_have = that.user.userInfo[that.get.key];
								that.pageData.wallet.cheques = "提现手续费" + that.appInit.commission_cheques;
								that.pageData.wallet.operate_name = '提现数量';
								if (that.tui.isDebug()) {
									that.param[that.get.tpl][that.get.key].account_name = '天机';
									that.param[that.get.tpl][that.get.key].name_phone = '13110447185';
									that.param[that.get.tpl][that.get.key].bank_of_deposit = '中国工商银行';
									that.param[that.get.tpl][that.get.key].bank_subbranch_of_deposit = '西安兴庆路南段支行';
									that.param[that.get.tpl][that.get.key].bank_no = '6215593700002730204';
									that.param[that.get.tpl][that.get.key].id_card = '612601199503200916';
								}
								break;
							case 'integral':
								that.pageData.wallet.operate_name = '转换数量';
								switch (that.get.to) {
									case 'u_species':
										that.pageData.wallet.now_have = parseInt(that.user.userInfo[that.get.key]) + '枚';
										that.pageData.wallet.cheques = "U币与积分兑换比例为" + that.appInit.integral2u_species;
										break;
									case 'commission':
										that.pageData.wallet.now_have = that.user.userInfo[that.get.key];
										that.pageData.wallet.cheques = "转换助农积分" + that.appInit.integral2commission;
										break;
								}
								console.log(that.pageData.wallet);
								break;
						}
						if (that.tui.isDebug()) {
							that.pageData.keyboard.numberArr = [1, 2, 3, 4, 5];
							that.pageData.keyboard.inputArr = ["●", "●", "●", "●", "●", ""];
						}
						break;
					case 'publicUserDetail':
						if (that.user.userInfo) {
							that.param[that.get.tpl].nick_name = that.user.userInfo.nick_name;
							that.param[that.get.tpl].real_name = that.user.userInfo.real_name;
							that.param[that.get.tpl].portrait = that.user.userInfo.portrait;
							that.param[that.get.tpl].tel = that.user.userInfo.tel;
							that.param[that.get.tpl].sex = that.user.userInfo.sexInt || 1;
						}
						console.log(that.param[that.get.tpl]);
						break;
					case 'manage_password':
					case 'password':
						that.pageData.btnSendCode.type = 'def';
						if (that.user.userInfo.tel.length === 0) {
							that.tui.toast("请先设定手机号！", false, function() {
								that.tui.urlHref('/pages/public-form?' + that.tui.initParamsData({
									title: "资料修改",
									tpl: 'publicUserDetail',
								}));
							}, 1500);
						}
						that.pageData.btnSendCode.paramValue = that.user.userInfo.tel;
						if (that.tui.isDebug()) {
							that.param[that.get.tpl].paddword = '123456';
							that.param[that.get.tpl].code = '123456';
						}
						break;
					default:
						console.log(that.get.tpl);
						break;
				}
				that.pageData.loading = true;
				that.$forceUpdate();
			},
			async formSubmit() {
				let that = this;
				let checkRes = "";
				let rules = [];
				let url = {};
				let response = {};
				switch (that.get.tpl) {
					case 'address':
						rules = [
							//
							{
								name: "full_name",
								rule: ["required", ],
								msg: ["请填写收货人姓名", ]
							},
							{
								name: "phone",
								rule: ["required", "isMobile"],
								msg: ["请输入收货人手机号码", "请输入正确的手机号码"]
							},
							{
								name: "province",
								rule: ["required", ],
								msg: ["请选择省市区", ]
							},
							{
								name: "city",
								rule: ["required", ],
								msg: ["请选择省市区", ]
							},
							{
								name: "district",
								rule: ["required", ],
								msg: ["请选择省市区", ]
							},
							{
								name: "info",
								rule: ["required"],
								msg: ["请输入详细地址"]
							}
						];
						url = {
							link: that.xhrUrl,
							param: {
								type: that.get.tpl
							},
							fun: "POST",
						};
						if (that.param[that.get.tpl].id != 0) {
							url.param.id = that.param[that.get.tpl].id;
						}
						break;
					case 'publicUserDetail':
						url = {
							link: that.xhrUrl,
							param: {
								type: that.get.tpl
							},
							fun: "POST",
						};
						if (typeof(that.param[that.get.tpl].portrait) === 'object') {
							that.param[that.get.tpl].portrait = that.param[that.get.tpl].portrait.value;
						}
						break;
					case 'wallet':
						switch (that.get.key) {
							case 'u_species':
								rules = [
									//
									{
										name: "price",
										rule: ["required", 'isNum'],
										msg: ["请填写操作数量", "操作数量需为整数"]
									},
									{
										name: "to_member_username",
										rule: ["required", ],
										msg: ["请输入会员登录账号", ],
									},
								];
								break;
							case 'commission':
								rules = [
									//
									{
										name: "account_name", //开户姓名
										rule: ["required", 'isChinese'],
										msg: ["请填写开户姓名", "开户姓名格式有误"]
									},
									{
										name: "name_phone", //实名手机
										rule: ["required", 'isMobile'],
										msg: ["请填写实名手机", "实名手机格式有误"]
									},
									{
										name: "bank_of_deposit", //开户银行
										rule: ["required", ],
										msg: ["请填写操作数量", ]
									},
									{
										name: "bank_subbranch_of_deposit", //开户支行
										rule: ["required", ],
										msg: ["请填写操作数量", ]
									},
									{
										name: "bank_no", //银行卡号
										rule: ["required", 'isNum'],
										msg: ["请填写银行卡号", "银行卡号格式有误"]
									},
									{
										name: "id_card", //身份账号
										rule: ["required", 'isIdCard'],
										msg: ["请填写身份账号", "身份账号格式有误"]
									},
									{
										name: "price",
										rule: ["required", 'isNum'],
										msg: ["请填写操作数量", "操作数量需为整数"]
									},
								];
								break;
							case 'integral':
								rules = [
									//
									{
										name: "price",
										rule: ["required", 'isNum'],
										msg: ["请填写操作数量", "操作数量需为整数"]
									},
								];
								break;
						}
						break;
					case 'recharge':
						url = {
							link: that.xhrUrl,
							param: {
								type: that.get.tpl,
								field: that.get.key,
								static: 'now',
							},
							fun: "POST",
						};
						switch (that.get.key) {
							case 'u_species':
								rules = [
									//
									{
										name: "price",
										rule: ["required", 'isNum'],
										msg: ["请填写操作数量", "操作数量需为整数"]
									},
									{
										name: "to_member_username",
										rule: ["required", ],
										msg: ["请输入会员登录账号", ],
									},
								];
								break;
						}
						break;
					case 'manage_password':
						if (/^[-]?\d{6}$/.test(that.param[that.get.tpl].paddword) === false) {
							that.tui.toast("请输入6位操作密码！", false, function() {}, 1500);
							return;
						}
						response = await that.tui.put('/code', {
							value: that.pageData.btnSendCode.paramValue,
							code: that.param[that.get.tpl].code,
						}, {
							type: that.pageData.btnSendCode.type,
						}, false, true, false);
						switch (response.status) {
							case 0:
								that.tui.post('/user/init', {
									manage_password: that.param[that.get.tpl].paddword,
								}, {
									timestamp: that.tui.formatDate().timestamp,
								}, true, true, false).then(function(res) {
									that.tui.toast('修改成功', false, function() {
										that.tui.urlBack(1);
									}, 1500);
								});
								break;
						}
						break;
					case 'password':
						if (/^[-]?\d{6}$/.test(that.param[that.get.tpl].paddword) === false) {
							that.tui.toast("请输入6位操作密码！", false, function() {}, 1500);
							return;
						}
						response = await that.tui.put('/code', {
							value: that.pageData.btnSendCode.paramValue,
							code: that.param[that.get.tpl].code,
						}, {
							type: that.pageData.btnSendCode.type,
						}, false, true, false);
						switch (response.status) {
							case 0:
								that.tui.post('/user/init', {
									password: that.param[that.get.tpl].paddword,
								}, {
									timestamp: that.tui.formatDate().timestamp,
								}, true, true, false).then(function(res) {
									that.tui.toast('修改成功', false, function() {
										that.tui.urlBack(1);
									}, 1500);
								});
								break;
						}
						break;
					default:
						console.log(that.param[that.get.tpl]);
						break;
				}
				switch (that.get.tpl) {
					case 'manage_password':
					case 'password':
						break;
					case 'wallet':
						//进行表单检查
						checkRes = formCheck.validation(that.param[that.get.tpl][that.get.key], rules);
						if (checkRes) {
							that.tui.toast(checkRes + "！", false, function() {}, 1500);
							return;
						}
						that.pageData.keyboard.status = true;
						break;
					case 'recharge':
						//进行表单检查
						checkRes = formCheck.validation(that.param[that.get.tpl][that.get.key], rules);
						if (checkRes) {
							that.tui.toast(checkRes + "！", false, function() {}, 1500);
							return;
						}
						response = await that.tui.post(url.link, that.param[that.get.tpl][that.get.key], url.param);
						that.tui.toast(response.info, false, function() {
							switch (response.status) {
								case 0:
									that.tui.setUserInfo(response.data, function(response) {
										that.tui.urlBack(parseInt(1));
									});
									break;
							}
						}, 1500);
						break;
					default:
						//进行表单检查
						checkRes = formCheck.validation(that.param[that.get.tpl], rules);
						if (checkRes) {
							that.tui.toast(checkRes + "！", false, function() {}, 1500);
							return;
						}
						switch (url.fun) {
							case "POST":
								response = await that.tui.post(url.link, that.param[that.get.tpl], url.param);
								break;
							case "PUT":
								response = await that.tui.put(url.link, that.param[that.get.tpl], url.param);
								break;
						}
						that.tui.toast(response.info, false, function() {
							switch (response.status) {
								case 0:
									switch (that.get.tpl) {
										case 'address':
											that.tui.setCache('lastUppAddressData', response.data, function() {
												switch (that.get.callback) {
													case 'def':
														that.tui.urlBack(parseInt(that.get.retreat));
														return;
													case 'cart':
														that.tui.urlBack(parseInt(that.get.retreat));
														return;
												}
											});
											break;
										case 'publicUserDetail':
											that.tui.setUserInfo(response.data, function(response) {});
											break;
										default:
											break;
									}
									break;
							}
						}, 1500);
						break;
				}
			},
			async detail(type, item) {
				let that = this;
				switch (that.get.tpl) {
					default:
						console.log(that.get.tpl, key);
						break;
				}
				that.$forceUpdate();
			},
			closeKeyboard() {
				let that = this;
				that.pageData.keyboard.numberArr = [];
				that.pageData.keyboard.status = false;
				that.pageData.keyboard.inputArr = that.pageData.keyboard.tempArr;
				if (that.tui.isDebug()) {
					that.pageData.keyboard.numberArr = [1, 2, 3, 4, 5];
					that.pageData.keyboard.inputArr = ["●", "●", "●", "●", "●", ""];
				}
			},
			async keyboardClick(e) {
				let that = this;
				let index = e.index;
				let numberArr = that.pageData.keyboard.numberArr;
				let inputArr = that.pageData.keyboard.inputArr;
				if (numberArr.length === inputArr.length || index == undefined) {
					return;
				}
				switch (index) {
					case 9: //取消键
						that.closeKeyboard();
						return;
					case 11: //退格键
						let len = numberArr.length;
						if (len) {
							inputArr.splice(len - 1, 1, "");
						} else {
							inputArr = that.pageData.keyboard.tempArr;
						}
						numberArr.pop();
						break;
					case 10:
						numberArr.push(0);
						inputArr.splice(numberArr.length - 1, 1, "●");
						break;
					default:
						numberArr.push(index + 1);
						inputArr.splice(numberArr.length - 1, 1, "●");
						break;
				}
				if (numberArr.length === inputArr.length) {
					let checkResponse = await that.tui.put('/user/init', {
						manage_password: that.tui.arr2str(numberArr, '')
					}, {
						verify: 'manage_password',
					}, true, false, false);
					that.closeKeyboard();
					switch (checkResponse.status) {
						case 0:
							switch (that.get.key) {
								case 'u_species':
									let giveResponse = await that.tui.post(that.xhrUrl, that.param[that.get.tpl][that.get.key], {
										type: 'give',
										field: that.get.key,
									}, true, false, false);
									that.tui.toast(giveResponse.info, false, function() {
										switch (giveResponse.status) {
											case 0:
												that.tui.setUserInfo(giveResponse.data, function(giveResponse) {
													that.tui.urlBack(1);
												});
												break;
										}
									}, 1500);
									break;
								case 'commission':
									let withdrawalResponse = await that.tui.post(that.xhrUrl, that.param[that.get.tpl][that.get.key], {
										type: 'withdrawal',
										field: that.get.key,
									}, true, false, false);
									that.tui.toast(withdrawalResponse.info, false, function() {
										switch (withdrawalResponse.status) {
											case 0:
												that.tui.setUserInfo(withdrawalResponse.data, function(withdrawalResponse) {
													that.tui.urlBack(1);
												});
												break;
										}
									}, 1500);
									break;
								case 'integral':
									let convertResponse = await that.tui.post(that.xhrUrl, that.param[that.get.tpl][that.get.key], {
										type: 'convert',
										field: that.get.key,
										to: that.get.to,
									}, true, false, false);
									that.tui.toast(convertResponse.info, false, function() {
										switch (convertResponse.status) {
											case 0:
												that.tui.setUserInfo(convertResponse.data, function(convertResponse) {
													that.tui.urlBack(1);
												});
												break;
										}
									}, 1500);
									break;
							}
							break;
						default:
							that.tui.toast(checkResponse.info + "！", false, function() {}, 1500);
							break;
					}
					return;
				}
			},
			saveSwitch(e) {
				let that = this;
				switch (that.get.tpl) {
					case 'address':
						that.param[that.get.tpl].is_default = e.detail.value;
						break;
					default:
						console.log(that.get.tpl, key);
						break;
				}
				that.$forceUpdate();
			},
			back() {
				let that = this;
				that.tui.urlBack(1);
			},
			initNavigation(e) {
				let that = this;
				that.header.opacity = e.opacity;
				that.header.top = e.top;
				that.$forceUpdate();
			},
			changeNavigation(e) {
				let that = this;
				that.header.opacity = e.opacity;
				that.$forceUpdate();
			},
			async btnSendCode() {
				let that = this;
				let checkRes = formCheck.validation({
					value: that.pageData.btnSendCode.paramValue,
				}, [
					// 
					{
						name: "value",
						rule: ["required", "isMobile"],
						msg: ["请输入登录手机号", "请输入正确的手机号"]
					},
				]);
				if (checkRes) {
					that.tui.toast(checkRes + "！", false, function() {}, 1500);
					return;
				}
				let response = await that.tui.post('/code', {
					value: that.pageData.btnSendCode.paramValue,
				}, {
					type: that.pageData.btnSendCode.type,
				}, false, true, false);
				that.tui.toast(response.info, false, function() {
					switch (response.status) {
						case 0:
							that.pageData.btnSendCode.btnType = 'gray';
							that.pageData.btnSendCode.disabled = true;
							let seconds = that.pageData.btnSendCode.timeSite - 1;
							that.pageData.btnSendCode.btnText = seconds + 's后获取';
							let countdown = setInterval(() => {
								if (seconds > 0) {
									that.pageData.btnSendCode.btnText = seconds + 's后获取';
									seconds--;
								} else {
									that.pageData.btnSendCode.btnType = that.tui.getColorSite().button.type;
									that.pageData.btnSendCode.disabled = false;
									that.pageData.btnSendCode.btnText = '获取验证码';
									clearInterval(countdown);
								}
							}, 1000);
							break;
						default:
							break;
					}
				}, 1500);
			},
			async onChangeGender(e) {
				let that = this;
				switch (that.get.tpl) {
					case 'publicUserDetail':
						that.param[that.get.tpl].sex = e.detail.value;
						break;
					default:
						let setWxGender = await that.tui.post(that.xhrUrl, {
							sex: e.detail.value,
						});
						that.tui.setUserInfo(setWxGender.data, function(response) {
							that.param[that.get.tpl].sex = setWxGender.data.userInfo.sex;
							console.log("缓存建立", setWxGender, that.param[that.get.tpl]);
							that.$forceUpdate();
						});
						break;
				}
			},
			async changeAvatar(e) {
				let that = this;
				that.tui.chooseImageToBase64(1, function(tempFilePaths, paths) {
					that.tui.uploadFile(tempFilePaths[0], 'portrait', {}, false).then(function(uploadFile) {
						switch (that.get.tpl) {
							case 'publicUserDetail':
								that.param[that.get.tpl].portrait = uploadFile.data;
								break;
							default:
								console.log(uploadFile);
								break;
						}
						that.$forceUpdate();
					});
				});
			},
			async onChooseAvatar(e) {
				let that = this;
				let uploadFile = await that.tui.uploadFile(e.detail.avatarUrl, 'wx_avatar_url', {}, false);
				let setWxAvatarUrl = await that.tui.post(that.xhrUrl, {
					wx_applet_data: {
						wx_avatar_url: uploadFile.data.url,
					},
				});
				that.tui.setUserInfo(setWxAvatarUrl.data, function(response) {
					that.param[that.get.tpl].wx_avatar_url = setWxAvatarUrl.data.userInfo.wx_applet_data.wx_avatar_url;
					console.log("缓存建立", setWxAvatarUrl, that.param[that.get.tpl]);
					that.$forceUpdate();
				});
			},
			async onChangeNickname(e) {
				let that = this;
				let setWxNickName = await that.tui.post(that.xhrUrl, {
					wx_applet_data: {
						wx_nick_name: e.detail.value,
					},
				});
				that.tui.setUserInfo(setWxNickName.data, function(response) {
					that.param[that.get.tpl].wx_nick_name = setWxNickName.data.userInfo.wx_applet_data.wx_nick_name;
					console.log("缓存建立", setWxNickName, that.param[that.get.tpl]);
					that.$forceUpdate();
				});
			},
			p2c2dInit(e) {
				let that = this;
				let value = e.detail.value;
				switch (that.get.tpl) {
					case 'address':
						that.param[that.get.tpl].province = that.pageData.site.selectList[value[0]].name;
						that.param[that.get.tpl].city = that.pageData.site.selectList[value[0]].childlist[value[1]].name;
						that.param[that.get.tpl].district = that.pageData.site.selectList[value[0]].childlist[value[1]].childlist[value[2]].name;
						that.pageData.site.addressValueString = '';
						that.pageData.site.addressValueString += that.param[that.get.tpl].province + ' ';
						that.pageData.site.addressValueString += that.param[that.get.tpl].city + ' ';
						that.pageData.site.addressValueString += that.param[that.get.tpl].district;
						break;
					default:
						console.log(that.get.tpl, key);
						break;
				}
				that.$forceUpdate();
			},
			changePicker(e) {
				let that = this;
				let column = e.detail.column;
				let value = e.detail.value;
				if (that.pageData.site.selectList[value].childlist.length === 0) {
					that.pageData.site.selectList[value].childlist[0] = that.pageData.site.selectList[value];
					that.pageData.site.selectList[value].childlist[0].childlist[0] = that.pageData.site.selectList[value];
				}
				if (column === 0) {
					that.pageData.site.multiArray = [];
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList));
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[value].childlist));
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[value].childlist[0].childlist));
					that.pageData.site.addressValue = [value, 0, 0];
				}
				if (column === 1) {
					that.pageData.site.multiArray = [];
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList));
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[that.pageData.site.addressValue[0]].childlist));
					that.pageData.site.multiArray.push(that.tui.obj2arr(that.pageData.site.selectList[that.pageData.site.addressValue[0]].childlist[value].childlist));
					that.pageData.site.addressValue = [that.pageData.site.addressValue[0], value, 0];
				}
				that.$forceUpdate();
			},
		},
		// 监听页面隐藏
		onHide() {
			let that = this;
			// that.pageData.loading = false;
		},
		// 监听页面卸载
		onUnload() {
			let that = this;
		},
		// 页面返回
		onBackPress() {
			let that = this;
		},
		// #ifdef MP
		onShareAppMessage() {
			// console.log('分享!')
		},
		// #endif
	}
</script>

<style scoped lang="scss">
	.container{
		background-color: #fff;
	}

</style>